//
//  ArroundTableViewCell.m
//  GoShops
//
//  Created by zcj on 15-12-7.
//  Copyright (c) 2015年 郑朝军. All rights reserved.
//

#import "ArroundTableViewCell.h"
#import "ArroundModel.h"
#import "Grouble.h"

@interface ArroundTableViewCell()
// 名称
@property (nonatomic,weak)UILabel* shopNameLabel;
// 地址
@property (nonatomic,weak)UILabel * xingxing;
// 价格
@property (nonatomic,weak)UILabel* priceLabel;
// 多少人评价
@property (nonatomic,weak)UILabel* evaluation;
@end

@implementation ArroundTableViewCell
+ (instancetype)ArroundTableViewCell:(UITableView *)tableView
{
    static NSString *ID = @"arroundtablecell";
    ArroundTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[ArroundTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    // 设置不能选中,选中每反应
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.userInteractionEnabled = YES;
        [self.imageView setImage:[UIImage imageNamed:@"bg_customReview_image_default"]];
        UIView * backView = [[UIView alloc]init];
        backView.frame = CGRectMake(0, 0, ScreenWidth, 120);
        backView.backgroundColor = [UIColor clearColor];
        [self addSubview:backView];
        
        CGFloat margn = 10;
        CGFloat shopImageW = 100;
        CGRect shopImg = CGRectMake(margn, margn, shopImageW, shopImageW);
        self.imageView.frame = shopImg;
        
        NSString * nameStr = @"小样";
        CGFloat nameX = CGRectGetMaxX(shopImg) + 2*margn;
        CGSize nameH = [nameStr sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20]}];
        CGFloat nameW = ScreenWidth - 80 - margn * 5;
        
        CGRect shopNameLabelRect = CGRectMake(nameX, margn, nameW, nameH.height);
        UILabel* shopNameLabel = [[UILabel alloc]initWithFrame:shopNameLabelRect];
        shopNameLabel.font = [UIFont systemFontOfSize:16];
        
        [backView addSubview:shopNameLabel];
        self.shopNameLabel = shopNameLabel;
        // 星星
        CGFloat sunX = nameX;
        CGFloat sunY = margn*2 + nameH.height;
        CGFloat sunW = nameW;
        CGFloat sunH = nameH.height;
        CGRect sunRect = CGRectMake(sunX, sunY, sunW, sunH);
        //  地址
        UILabel * xingxing = [[UILabel alloc]init];
        
        xingxing.contentMode = UIViewContentModeLeft;
        
        xingxing.frame = sunRect;
        
        [backView addSubview:xingxing];
        self.xingxing = xingxing;
        
        // 多少人评价
        CGFloat evaluationX = nameX + 6 *margn;
        CGFloat evaluationY = sunY;
        CGFloat evaluationW = 120;
        CGFloat evaluationH = nameH.height;
        CGRect evaluationSize = CGRectMake(evaluationX, evaluationY, evaluationW, evaluationH);
        
        UILabel * evaluation = [[UILabel alloc]initWithFrame:evaluationSize];
        evaluation.textColor = [UIColor blackColor];
        
        
        evaluation.font = [UIFont systemFontOfSize:10];
        evaluation.textAlignment = NSTextAlignmentRight;
        
        [backView addSubview:evaluation];
        self.evaluation = evaluation;
        // 例子：美发  中关村
        CGFloat priceX = sunX;
        CGFloat priceY = CGRectGetMaxY(sunRect) + margn;
        CGFloat priceW = sunW;
        CGFloat priceH = sunH;
        CGRect priceRect = CGRectMake(priceX, priceY, priceW, priceH);
        
        UILabel * priceLabel = [[UILabel alloc]initWithFrame:priceRect];
        priceLabel.numberOfLines = 0;
        priceLabel.textColor = ZCJColor(85, 216, 182);
        priceLabel.font = [UIFont systemFontOfSize:20];
        priceLabel.textAlignment = NSTextAlignmentLeft;
        
        [backView addSubview:priceLabel];
        self.priceLabel = priceLabel;
        // Initialization code
    }
    return self;
}
- (void)setArroundModel:(ArroundModel *)arroundModel
{
    _arroundModel = arroundModel;
    ZCJLog(@"%@",arroundModel.name);
    [self.imageView setImageWithURL:[NSURL URLWithString:arroundModel.frontImg] placeholderImage:[UIImage imageNamed:@"shuishangzhangwei"]];
    
//    // 名称
//    @property (nonatomic,weak)UILabel* shopNameLabel;
//    // 地址
//    @property (nonatomic,weak)UILabel * xingxing;
//    // 价格
//    @property (nonatomic,weak)UILabel* priceLabel;
//    // 多少人评价
//    @property (nonatomic,weak)UILabel* evaluation;
    
    // 名称
//    @property(nonatomic,strong)NSString * name;
//    // 农家乐
//    @property(nonatomic,strong)NSString * cateName;
//    // 地点
//    @property(nonatomic,strong)NSString * areaName;
//    // 提供一个免费的停车场
//    @property(nonatomic,strong)NSString * parkingInfo;
//    // 多少钱
//    @property(nonatomic,strong)NSString * discount;
    //名称 地点
    self.shopNameLabel.text = [NSString stringWithFormat:@"%@   %@",arroundModel.name,arroundModel.areaName];
    //农家乐
    if (arroundModel.cateName.length == 0) {
        self.xingxing.text = @"九江市";
    }else{
        self.xingxing.text = arroundModel.cateName;
    }
    if (arroundModel.discount.length == 0) {
        self.priceLabel.text = @"123元";
    }else{
        // 多少钱
        self.priceLabel.text = arroundModel.discount;
    }
    //提供一个免费的停车场
    if (arroundModel.parkingInfo.length == 0) {
        self.evaluation.text = @"提供一个免费的停车场";
    }else{
        self.evaluation.text = arroundModel.parkingInfo;
    }
    
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat margn = 10;
    CGFloat shopImageW = 100;
    CGRect shopImg = CGRectMake(margn, margn, shopImageW, shopImageW);
    self.imageView.frame = shopImg;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
